package org.algorithm.biubiu.wheel_1.树;

import org.algorithm.common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jzx
 * @date 2022/5/30
 * @desc {https://leetcode.cn/problems/binary-tree-preorder-traversal/}
 */
public class $5月30二叉树的前序遍历 {


    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList();
        traversal(root,res);
        return res;
    }

    public void traversal(TreeNode root, List<Integer> res){
        if(root==null) return;

        res.add(root.val);
        traversal(root.left,res);
        traversal(root.right,res);

    }
}
